package com.qcc.week11.redislock;

/**
 * @创建人 qianchengcheng
 * @创建时间 2022/3/27
 * @描述
 */
public class StoreOperate {

    private final static String LOCK = "redis_lock";

    private final static int EXPIRE = 3;

    private static int amount = 15;

    /**
    *@描述 库存操作
    *@参数 []
    *@返回值 void
    *@创建人 qianchengcheng
    *@创建时间 2022/3/27
    *@修改人和其它信息
    */
    public static void storeOperate() {
        if (!RedisLock.getInstance().lock(LOCK, EXPIRE)) {
            System.out.println("获取锁失败");
            return;
        }
        try {
            Thread.sleep(10000);
            amount -= 1;
            System.out.printf("库存减一 amount: %d\n", amount);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        RedisLock.getInstance().release(LOCK);
    }
}
